<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>prencar: D:/Workspace/Arduino/prencar/Command.cpp Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="prencar.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">prencar
   &#160;<span id="projectnumber">1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('_command_8cpp.html','');
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">D:/Workspace/Arduino/prencar/Command.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_command_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include &quot;<a class="code" href="_command_8h.html">Command.h</a>&quot;</span>
<a name="l00002"></a>00002 
<a name="l00006"></a><a class="code" href="class_command.html#a18df2d81039392daeb0b78c346a70537">00006</a> <a class="code" href="class_command.html#a18df2d81039392daeb0b78c346a70537">Command::Command</a>(){
<a name="l00007"></a>00007 <span class="comment">//  _com = Communication::getInstance();</span>
<a name="l00008"></a>00008   <a class="code" href="class_command.html#a31842ee183ae2cd06ce6ad8f7533ff02">commandCode</a> = 0;
<a name="l00009"></a>00009 }
<a name="l00010"></a>00010 
<a name="l00015"></a><a class="code" href="class_command.html#adbc9f2539741be419397502840f3740c">00015</a> <span class="keywordtype">void</span> <a class="code" href="class_command.html#adbc9f2539741be419397502840f3740c">Command::parse</a>(byte* commandString){
<a name="l00016"></a>00016   <span class="keywordtype">int</span> commandIndex = 0;
<a name="l00017"></a>00017   <span class="keywordtype">int</span> tempStringSize = 6;  <span class="comment">//6 which includes the biggest int char and a \0 character</span>
<a name="l00018"></a>00018   byte tempString[tempStringSize];
<a name="l00019"></a>00019   commandIndex = <a class="code" href="class_command.html#ad23d2c8f8c6c24b71bae06c5aefcc537">copyBytesUntil</a>(commandString, commandIndex, tempString, tempStringSize, <span class="charliteral">&#39;-&#39;</span>);
<a name="l00020"></a>00020   <a class="code" href="class_command.html#a31842ee183ae2cd06ce6ad8f7533ff02">commandCode</a> = atoi((<span class="keywordtype">char</span>*)tempString);
<a name="l00021"></a>00021   commandIndex++; <span class="comment">//plus the &quot;-&quot; character</span>
<a name="l00022"></a>00022   commandIndex += <a class="code" href="class_command.html#ad23d2c8f8c6c24b71bae06c5aefcc537">copyBytesUntil</a>(commandString, commandIndex, tempString, tempStringSize, <span class="charliteral">&#39;:&#39;</span>);
<a name="l00023"></a>00023   <a class="code" href="class_command.html#adc423454c3b30e6b2fe33f8a84ff9fde">amountOfParameters</a> = atoi((<span class="keywordtype">char</span>*)tempString);
<a name="l00024"></a>00024   <span class="comment">//check if that&#39;s not to many parameters</span>
<a name="l00025"></a>00025   <span class="keywordflow">if</span>(<a class="code" href="class_command.html#adc423454c3b30e6b2fe33f8a84ff9fde">amountOfParameters</a> &gt; <a class="code" href="class_command.html#af0aca7db3a739923260c8a8a35820b7f" title="Defines, how many parameters a command can have.">_COMMANDMAXPARAMETERAMOUNT</a>){
<a name="l00026"></a>00026     <span class="comment">//this is an error and should not happen. However if it is the case, make sure no data will be overwritten accidently.</span>
<a name="l00027"></a>00027     <span class="keywordflow">return</span>;
<a name="l00028"></a>00028   }
<a name="l00029"></a>00029   commandIndex++; <span class="comment">//plus the &quot;:&quot; character</span>
<a name="l00030"></a>00030   <span class="comment">//get all the parameters</span>
<a name="l00031"></a>00031   <span class="keywordtype">int</span> i;
<a name="l00032"></a>00032   <span class="keywordflow">for</span>(i = 0; i &lt; <a class="code" href="class_command.html#adc423454c3b30e6b2fe33f8a84ff9fde">amountOfParameters</a> - 1; i++){
<a name="l00033"></a>00033     commandIndex += <a class="code" href="class_command.html#ad23d2c8f8c6c24b71bae06c5aefcc537">copyBytesUntil</a>(commandString, commandIndex, tempString, tempStringSize, <span class="charliteral">&#39;,&#39;</span>);
<a name="l00034"></a>00034     <a class="code" href="class_command.html#a213973ca7ffaf1385a959ceab49f5065">parameters</a>[i] = atoi((<span class="keywordtype">char</span>*)tempString);
<a name="l00035"></a>00035     commandIndex++; <span class="comment">//plus the &quot;,&quot; character</span>
<a name="l00036"></a>00036   }
<a name="l00037"></a>00037   <span class="keywordflow">if</span>(amountOfParameters &gt; 0){
<a name="l00038"></a>00038     commandIndex += <a class="code" href="class_command.html#ad23d2c8f8c6c24b71bae06c5aefcc537">copyBytesUntil</a>(commandString, commandIndex, tempString, tempStringSize, <span class="charliteral">&#39;\n&#39;</span>);
<a name="l00039"></a>00039     <a class="code" href="class_command.html#a213973ca7ffaf1385a959ceab49f5065">parameters</a>[i] = atoi((<span class="keywordtype">char</span>*)tempString);
<a name="l00040"></a>00040   }
<a name="l00041"></a>00041   <span class="comment">//_com-&gt;send(commandCode, parameters, amountOfParameters);</span>
<a name="l00042"></a>00042 }
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="comment">/*</span>
<a name="l00045"></a>00045 <span class="comment"> * Copies characters from the source to the target until the source character matches the stopCharacter or</span>
<a name="l00046"></a>00046 <span class="comment"> * the size of the target -1 (-1 because of the \\0 character) is reached.</span>
<a name="l00047"></a>00047 <span class="comment"> * @param source Source string from which the data is taken.</span>
<a name="l00048"></a>00048 <span class="comment"> * @param sourceStart From which character the copy process shall be started.</span>
<a name="l00049"></a>00049 <span class="comment"> * @param target Where the data shall be copied to.</span>
<a name="l00050"></a>00050 <span class="comment"> * @param stopCharacter Character that will stop the copy process.</span>
<a name="l00051"></a>00051 <span class="comment"> * @return How many bytes were copied (without the \\0 that will be added always at the end).</span>
<a name="l00052"></a>00052 <span class="comment"> */</span>
<a name="l00053"></a><a class="code" href="class_command.html#ad23d2c8f8c6c24b71bae06c5aefcc537">00053</a> <span class="keywordtype">int</span> <a class="code" href="class_command.html#ad23d2c8f8c6c24b71bae06c5aefcc537">Command::copyBytesUntil</a>(byte* <span class="keyword">const</span> source, <span class="keywordtype">int</span> sourceStart, byte* target, <span class="keywordtype">int</span> targetSize, byte stopCharacter){
<a name="l00054"></a>00054   <span class="comment">//iterate through the characters. -2 because of the \0 character for that we will need some space as well at the end.</span>
<a name="l00055"></a>00055   <span class="keywordtype">int</span> i;
<a name="l00056"></a>00056   <span class="keywordflow">for</span>(i = 0; i &lt; targetSize - 1; i++){
<a name="l00057"></a>00057     <span class="keywordflow">if</span>(source[sourceStart + i] == stopCharacter){
<a name="l00058"></a>00058       <span class="keywordflow">break</span>;
<a name="l00059"></a>00059     }
<a name="l00060"></a>00060     target[i] = source[sourceStart + i];
<a name="l00061"></a>00061   }
<a name="l00062"></a>00062   target[i] = <span class="charliteral">&#39;\0&#39;</span>;
<a name="l00063"></a>00063   <span class="keywordflow">return</span> i;
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065 
</pre></div></div><!-- contents -->
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="_command_8cpp.html">Command.cpp</a>      </li>

    <li class="footer">Generated on Tue Apr 3 2012 18:43:12 for prencar by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.0 </li>
   </ul>
 </div>


</body>
</html>
